import { Component, Injector, ViewChild } from '@angular/core';
import { IonicPage, NavController, NavParams, Slides } from 'ionic-angular';
import { BasePage } from '../../basePage';
import { StorageService } from '../../../providers/StorageService';
import { UserService } from '../../../providers/UserService';
import { PIC_URL } from "../../../providers/Config";
import { Events } from 'ionic-angular';
declare var Swiper;
/**
 * Generated class for the ConsumerorderPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-consumerorder',
  templateUrl: 'consumerorder.html',
})

export class ConsumerorderPage extends BasePage {
  id: any;
  swiper: any;
  picrooturl = "";//图片服务地址
  userinfo = {}//获取内存中的数据
  // orderlist1=[];   //全部订单
  // orderlist2=[];   //未使用订单
  // orderlist3=[];    //未评价订单
  // orderlist4=[];   //退款订单

  @ViewChild('contentSlides') contentSlides: Slides;
  items: Array<any> = [0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8];
  menus: Array<string> = ["全部", "待服务", "待评价","退款"];
  /*用来保存加载当前 页面 需要显示的子页面 */
  stuPage: any;

  constructor(injector: Injector, public events: Events,public userService: UserService, public stc: StorageService) {
    super(injector);
    this.picrooturl = PIC_URL;
    this.userinfo = this.stc.read('userinfo');
    // this.getMyOrderListAPI();
  }

  ionViewDidLoad() {
    this.id = this.navParams.get('id')
    console.log(this.id)
    console.log('我已经执行');
    this.initSwiper();
    // if (this.id == 6) {
    //   this.selectPageMenu(event, 6)
    // }
    this.stuPage = this.navParams.data.stu;
    console.log(this.navParams.data);
  }

  /*页面要进入的时候执行的函数  再页面加载之后执行  页面中一些函数已经执行完成  所以this.contentSliders 函数已经解析完成 */
  ionViewWillEnter(){
    console.log(this.stc.read("back"))
    if(this.stc.read("back") != null){
      this.stuPage=this.stc.read("back");
    }
    // this.stuPage = this.navParams.data.stu;
    let index = parseInt(this.stuPage);
    this.setStyle(index);
    this.contentSlides.slideTo(index,0);
  }
  //获取消费者订单
  // async getMyOrderListAPI() {
  //   let param = { "user_id": this.userinfo['user_id'], "order_type": 0 };
  //   let loader = this.loadingCtrl.create({
  //     content: "",
  //   });
  //   let result = await this.userService.getMyOrderListAPI(param);
  //   loader.dismiss();
  //   console.log(result)
  //   if (result.code == 1) {
  //       //全部订单
  //       this.orderlist1 = result.data.filter((e)=>{
  //         return e.order_status !=-1 && e.order_status !=5 && e.order_status != -4;
  //       })
  //       //未使用订单
  //       this.orderlist2= result.data.filter((e)=>{
  //           return e.order_status==2
  //       })
  //       //未评价
  //       this.orderlist3= result.data.filter((e)=>{
  //           return e.order_status==3
  //       })
  //       this.orderlist4=result.data.filter((e)=>{
  //          return e.order_status==-2||e.order_status==-3
  //       })
  //   } else {
  //     this.showAlert(result.msg);
  //   }
  // }

  initSwiper() {
    this.swiper = new Swiper('.pageMenuSlides .swiper-container', {
      slidesPerView: 4,
      spaceBetween: 0,
      breakpoints: {
        1024: {
          slidesPerView: 4,
          spaceBetween: 0
        },
        768: {
          slidesPerView: 4,
          spaceBetween: 0
        },
        640: {
          slidesPerView: 4,
          spaceBetween: 0
        },
        320: {
          slidesPerView: 4,
          spaceBetween: 0
        }
      }
    });
  }


  /**点击选择 */
  selectPageMenu($event, index) {
    console.log(index);
    this.setStyle(index);
    this.contentSlides.slideTo(index);
  }
  /**滑动选择 */
  slideChanged() {
    let index = this.contentSlides.getActiveIndex();
    this.setStyle(index);
    this.swiper.slideTo(index, 300);
  }

  /**样式切换选中 */
  setStyle(index) {
    var slides = document.getElementsByClassName('pageMenuSlides')[0].getElementsByClassName('swiper-slide');
    if (index < slides.length) {
      for (var i = 0; i < slides.length; i++) {
        var s = slides[i];
        s.className = "swiper-slide";
      }
      slides[index].className = "swiper-slide bottomLine";
    }
  }

  /**上一个页面 */
  dismissCLI() {
    this.stc.removeItem("back");
    this.viewCtrl.dismiss();
  }

}
